﻿Public Class VACDURATIONCLASS
    Dim connect As CONDB = CONDB.NewConnection()

    Private VDID As Integer = Nothing
    Private VACCINEID As Integer = Nothing
    Private CNO As Integer = Nothing
    Private SPAN As Integer = Nothing
    Private MAXSPAN As Integer = Nothing
    Private STATUS = Nothing
    Private selectVacduration = "SELECT a.`vdid` AS 'ID', a.`vaccineid` AS 'รหัสวัคซีน', b.`vaccine_en` AS 'ชื่อสากล', b.`vaccine_th` AS 'ชื่อไทย', b.`remark` AS 'หมายเหตุ', a.`cno` AS 'ลำดับเข็ม', a.`span` AS 'อายุที่ฉีด', a.`maxspan` AS 'อายุที่ฉีดสูงสุด', a.`status` AS 'สถานะการเปิดใช้งาน' FROM vacduration a LEFT JOIN masvaccine b ON a.vaccineid = b.vaccineid"

    Property VDID_ As Integer
        Get
            Return VDID
        End Get
        Set(value As Integer)
            VDID = value
        End Set
    End Property

    Property VACCINEID_ As Integer
        Get
            Return VACCINEID
        End Get
        Set(value As Integer)
            VACCINEID = value
        End Set
    End Property

    Property CNO_ As Integer
        Get
            Return CNO
        End Get
        Set(value As Integer)
            CNO = value
        End Set
    End Property
    Property SPAN_ As Integer
        Get
            Return SPAN
        End Get
        Set(value As Integer)
            SPAN = value
        End Set
    End Property

    Property MAXSPAN_ As Integer
        Get
            Return MAXSPAN
        End Get
        Set(value As Integer)
            MAXSPAN = value
        End Set
    End Property

    Property STATUS_ As Boolean
        Get
            Return STATUS
        End Get
        Set(value As Boolean)
            If value = True Then
                STATUS = 1
            Else
                STATUS = 0
            End If
        End Set
    End Property

    Property selectVacduration_ As String
        Get
            Return selectVacduration
        End Get
        Set(value As String)
            selectVacduration = value
        End Set
    End Property

    Public Function insertVacduration() As Boolean
        If connect.GetTable("SELECT vdid FROM vacduration WHERE vaccineid = '" & VACCINEID & "' AND span = '" & SPAN & "'").Rows.Count > 0 Then
            MsgBox("ไม่สามารถเพิ่มเวลาในการฉีดได้ เนื่องจากมีรูปแบบเวลาการฉีดนี้อยู่ในระบบแล้ว")
        Else
            Dim sql As String = "INSERT INTO vacduration (vaccineid, cno, span, maxspan, status) VALUES ('" & VACCINEID & "', '" & CNO & "', '" & SPAN & "', '" & MAXSPAN & "', '" & STATUS & "')"

            Try
                connect.BeginTrans()
                connect.ExecuteNonQuery(sql)
                connect.CommitTrans()
                connect.Dispose()
                Return True
            Catch ex As Exception
                connect.Dispose()
                MsgBox(ex.ToString)
                Return False
            End Try
        End If
    End Function

    Public Function editVacduration() As Boolean
        If connect.GetTable("SELECT vdid FROM vacduration WHERE vaccineid = '" & VACCINEID & "' AND span = '" & SPAN & "'").Rows.Count > 0 Then
            MsgBox("ไม่สามารถแก้ไขเวลาในการฉีดในรูปแบบดังกล่าวได้ เนื่องจากมีรูปแบบเวลาการฉีดนี้อยู่ในระบบแล้ว")
        Else
            Dim sql As String = "UPDATE vacduration SET vaccineid = '" & VACCINEID & "', cno = '" & CNO & "', span = '" & SPAN & "', maxspan = '" & MAXSPAN & "', status = '" & STATUS & "' WHERE vdid = '" & VDID & "'"
            Try
                connect.BeginTrans()
                connect.ExecuteNonQuery(sql)
                connect.CommitTrans()
                connect.Dispose()
                Return True
            Catch ex As Exception
                connect.Dispose()
                MsgBox(ex.ToString)
                Return False
            End Try
        End If
    End Function
End Class
